<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Class template discrete_distribution</title>
<link rel="stylesheet" href="../../../../doc/src/boostbook.css" type="text/css">
<meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
<link rel="home" href="../../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
<link rel="up" href="../../boost_random/reference.html#doxygen.headers.discrete__distribution_8hpp" title="Header &lt;boost/random/discrete_distribution.hpp&gt;">
<link rel="prev" href="classboost_1_1random_1_1discard__block__engine.html" title="Class template discard_block_engine">
<link rel="next" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table cellpadding="2" width="100%"><tr>
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../boost.png"></td>
<td align="center"><a href="../../../../index.html">Home</a></td>
<td align="center"><a href="../../../../libs/libraries.htm">Libraries</a></td>
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
<td align="center"><a href="../../../../more/index.htm">More</a></td>
</tr></table>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="classboost_1_1random_1_1discard__block__engine.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_random/reference.html#doxygen.headers.discrete__distribution_8hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
<div class="refentry">
<a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution"></a><div class="titlepage"></div>
<div class="refnamediv">
<h2><span class="refentrytitle">Class template discrete_distribution</span></h2>
<p>boost::random::discrete_distribution</p>
</div>
<h2 class="refsynopsisdiv-title">Synopsis</h2>
<div class="refsynopsisdiv"><pre class="synopsis"><span class="comment">// In header: &lt;<a class="link" href="../../boost_random/reference.html#doxygen.headers.discrete__distribution_8hpp" title="Header &lt;boost/random/discrete_distribution.hpp&gt;">boost/random/discrete_distribution.hpp</a>&gt;

</span><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> IntType <span class="special">=</span> <span class="keyword">int</span><span class="special">,</span> <span class="keyword">typename</span> WeightType <span class="special">=</span> <span class="keyword">double</span><span class="special">&gt;</span> 
<span class="keyword">class</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">{</span>
<span class="keyword">public</span><span class="special">:</span>
  <span class="comment">// types</span>
  <span class="keyword">typedef</span> <span class="identifier">WeightType</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a9205e2f8635c5c4c00d4f6329ad148db"></a><span class="identifier">input_type</span><span class="special">;</span> 
  <span class="keyword">typedef</span> <span class="identifier">IntType</span>    <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a562a84efeaf963efbd8d262a59a65a0a"></a><span class="identifier">result_type</span><span class="special">;</span>

  <span class="comment">// member classes/structs/unions</span>

  <span class="keyword">class</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">{</span>
  <span class="keyword">public</span><span class="special">:</span>
    <span class="comment">// types</span>
    <span class="keyword">typedef</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1acccc630aacc8eb119fd07f1838609a7f"><span class="identifier">distribution_type</span></a><span class="special">;</span>

    <span class="comment">// <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#id-1_3_32_5_6_10_1_1_1_3_2-bb">public member functions</a></span>
    <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1a861b7711f135ab7bc01d00c409d16fe5"><span class="identifier">param_type</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Iter<span class="special">&gt;</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1ade61ae9c4ebb8ea9ae8271e7fd12bbdd"><span class="identifier">param_type</span></a><span class="special">(</span><span class="identifier">Iter</span><span class="special">,</span> <span class="identifier">Iter</span><span class="special">)</span><span class="special">;</span>
    <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1a4f6e5aef4d818a850ce0a0af5a2efaf9"><span class="identifier">param_type</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">&gt;</span> <span class="keyword">explicit</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1af3b9b1da9b191cb1dd4391b74a9d21a3"><span class="identifier">param_type</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Func<span class="special">&gt;</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1a7d000cd1c8edadde06ed1894f5791e69"><span class="identifier">param_type</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="identifier">Func</span><span class="special">)</span><span class="special">;</span>
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1abd81e03872f5f99cc1e5628e287ae848"><span class="identifier">probabilities</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>

    <span class="comment">// <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#id-1_3_32_5_6_10_1_1_1_3_3-bb">friend functions</a></span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
      <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
      <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1a36d2820c7e758fa1a94fdd5d74949e54"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
      <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
      <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1aa94ff75dd5871ee80a6fc0a095c75bd0"><span class="keyword">operator</span><span class="special">&gt;&gt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">bool</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1ae6f3b58e629ce7a54b5e18a4f05dbc5a"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
    <span class="keyword">bool</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1_1param__type_1aa559d0d98e88e84417364a89b83cf5b2"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="special">}</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#id-1_3_32_5_6_10_1_1_1_6-bb">public member functions</a></span>
  <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a006a286517d16071dc930a8d3944eb40"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Iter<span class="special">&gt;</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1ac6b326c52f420c0710272dd60118d985"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="identifier">Iter</span><span class="special">,</span> <span class="identifier">Iter</span><span class="special">)</span><span class="special">;</span>
  <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a754a299898534f6b8be94e400ab0dd47"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">&gt;</span> <span class="keyword">explicit</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a480850a4c29f3d2ebdf16d278e4ed5e7"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Func<span class="special">&gt;</span> 
    <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1ac3af6ddce27b63682a21331c3d1b797b"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="keyword">double</span><span class="special">,</span> <span class="identifier">Func</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">explicit</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a98d0ea659919f23b5d2dcf2afea97cb7"><span class="identifier">discrete_distribution</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> <span class="identifier">IntType</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a5661a895fb42f7d69313a8ce71ca95cf"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> <span class="identifier">IntType</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a75279b4ccbcde054d74f1d6444bb9105"><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span></a><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span><span class="special">,</span> <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">result_type</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a5e09505aacda138bced472644237192b"><span class="identifier">min</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">result_type</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a6c545755b04ff52aa2ff3cf6e73e5f59"><span class="identifier">max</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a9f713d7094e82c668857c7762c0bf08a"><span class="identifier">probabilities</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a24387bac3d3961e3e91c160e78af20c3"><span class="identifier">param</span></a><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1abc9eb0c5f2098d39f1a8390b84ec9a9e"><span class="identifier">param</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">void</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a96ef439ac6014dc8fa3fad136a7a4db4"><span class="identifier">reset</span></a><span class="special">(</span><span class="special">)</span><span class="special">;</span>

  <span class="comment">// <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#id-1_3_32_5_6_10_1_1_1_7-bb">friend functions</a></span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
    <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a6d79d1fa37ce80bf01f5bd5324ace4c3"><span class="keyword">operator</span><span class="special">&lt;&lt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> 
               <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
    <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
    <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a32c7054cca68cc57d265cb419c1f4141"><span class="keyword">operator</span><span class="special">&gt;&gt;</span></a><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span><span class="special">,</span> 
               <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a3026c723cb18b563ed2b4c43c8cdaa90"><span class="keyword">operator</span><span class="special">==</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">,</span> 
                  <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
  <span class="keyword">bool</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a119f950ff56eeea03b439d36f6dabd0a"><span class="keyword">operator</span><span class="special">!=</span></a><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">,</span> 
                  <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span><span class="special">)</span><span class="special">;</span>
<span class="special">}</span><span class="special">;</span></pre></div>
<div class="refsect1">
<a name="id-1.3.32.5.6.9.3.4"></a><h2>Description</h2>
<p>The class <code class="computeroutput"><a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> models a  <a class="link" href="../../boost_random/reference.html#boost_random.reference.concepts.random_distribution" title="Random Distribution">random distribution</a> . It produces integers in the range [0, n) with the probability of producing each value is specified by the parameters of the distribution. </p>
<div class="refsect2">
<a name="id-1.3.32.5.6.9.3.4.3"></a><h3>
<a name="id-1_3_32_5_6_10_1_1_1_6-bb"></a><code class="computeroutput">discrete_distribution</code> public member functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a006a286517d16071dc930a8d3944eb40"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Creates a new <code class="computeroutput"><a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> object that has <span class="inlinemediaobject"><img src="../../images/random//form_4.png"></span> and <span class="inlinemediaobject"><img src="../../images/random//form_5.png"></span>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Iter<span class="special">&gt;</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1ac6b326c52f420c0710272dd60118d985"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="identifier">Iter</span> first<span class="special">,</span> <span class="identifier">Iter</span> last<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> from an iterator range. If <code class="computeroutput">first</code> == <code class="computeroutput">last</code>, equivalent to the default constructor. Otherwise, the values of the range represent weights for the possible values of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a754a299898534f6b8be94e400ab0dd47"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">initializer_list</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> wl<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <code class="computeroutput"><a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a></code> from a <code class="computeroutput">std::initializer_list</code>. If the <code class="computeroutput">initializer_list</code> is empty, equivalent to the default constructor. Otherwise, the values of the <code class="computeroutput">initializer_list</code> represent weights for the possible values of the distribution. For example, given the distribution</p>
<pre class="programlisting"><a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a006a286517d16071dc930a8d3944eb40"><span class="identifier">discrete_distribution</span><span class="special">&lt;</span><span class="special">&gt;</span></a> <span class="identifier">dist</span><span class="special">{</span><span class="number">1</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">5</span><span class="special">}</span><span class="special">;</span>
</pre>
<p>The probability of a 0 is 1/10, the probability of a 1 is 2/5, the probability of a 2 is 1/2, and no other values are possible. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Range<span class="special">&gt;</span> <span class="keyword">explicit</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a480850a4c29f3d2ebdf16d278e4ed5e7"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="keyword">const</span> <span class="identifier">Range</span> <span class="special">&amp;</span> range<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> from a Boost.Range range. If the range is empty, equivalent to the default constructor. Otherwise, the values of the range represent weights for the possible values of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> Func<span class="special">&gt;</span> 
  <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1ac3af6ddce27b63682a21331c3d1b797b"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">size_t</span> nw<span class="special">,</span> <span class="keyword">double</span> xmin<span class="special">,</span> <span class="keyword">double</span> xmax<span class="special">,</span> <span class="identifier">Func</span> fw<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> that approximates a function. If nw is zero, equivalent to the default constructor. Otherwise, the range of the distribution is [0, nw), and the weights are found by calling fw with values evenly distributed between <span class="inlinemediaobject"><img src="../../images/random//form_6.png"></span> and <span class="inlinemediaobject"><img src="../../images/random//form_7.png"></span>, where <span class="inlinemediaobject"><img src="../../images/random//form_8.png"></span>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">explicit</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a98d0ea659919f23b5d2dcf2afea97cb7"></a><span class="identifier">discrete_distribution</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span> param<span class="special">)</span><span class="special">;</span></pre>
<p>Constructs a <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> from its parameters. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> <span class="identifier">IntType</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a5661a895fb42f7d69313a8ce71ca95cf"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span> urng<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a value distributed according to the parameters of the <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> URNG<span class="special">&gt;</span> 
  <span class="identifier">IntType</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a75279b4ccbcde054d74f1d6444bb9105"></a><span class="keyword">operator</span><span class="special">(</span><span class="special">)</span><span class="special">(</span><span class="identifier">URNG</span> <span class="special">&amp;</span> urng<span class="special">,</span> <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span> param<span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a value distributed according to the parameters specified by param. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">result_type</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a5e09505aacda138bced472644237192b"></a><span class="identifier">min</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the smallest value that the distribution can produce. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">result_type</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a6c545755b04ff52aa2ff3cf6e73e5f59"></a><span class="identifier">max</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the largest value that the distribution can produce. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span> <span class="identifier">WeightType</span> <span class="special">&gt;</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a9f713d7094e82c668857c7762c0bf08a"></a><span class="identifier">probabilities</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns a vector containing the probabilities of each value of the distribution. For example, given</p>
<pre class="programlisting"><a class="link" href="classboost_1_1random_1_1discrete__distribution.html#doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a006a286517d16071dc930a8d3944eb40"><span class="identifier">discrete_distribution</span><span class="special">&lt;</span><span class="special">&gt;</span></a> <span class="identifier">dist</span> <span class="special">=</span> <span class="special">{</span> <span class="number">1</span><span class="special">,</span> <span class="number">4</span><span class="special">,</span> <span class="number">5</span> <span class="special">}</span><span class="special">;</span>
<span class="identifier">std</span><span class="special">::</span><span class="identifier">vector</span><span class="special">&lt;</span><span class="keyword">double</span><span class="special">&gt;</span> <span class="identifier">p</span> <span class="special">=</span> <span class="identifier">dist</span><span class="special">.</span><span class="identifier">param</span><span class="special">(</span><span class="special">)</span><span class="special">;</span>
</pre>
<p>the vector, p will contain {0.1, 0.4, 0.5}.</p>
<p>If <code class="computeroutput">WeightType</code> is integral, then the weights will be returned unchanged. </p>
</li>
<li class="listitem">
<pre class="literallayout"><a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a24387bac3d3961e3e91c160e78af20c3"></a><span class="identifier">param</span><span class="special">(</span><span class="special">)</span> <span class="keyword">const</span><span class="special">;</span></pre>
<p>Returns the parameters of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1abc9eb0c5f2098d39f1a8390b84ec9a9e"></a><span class="identifier">param</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html" title="Class param_type">param_type</a> <span class="special">&amp;</span> param<span class="special">)</span><span class="special">;</span></pre>
<p>Sets the parameters of the distribution. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">void</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a96ef439ac6014dc8fa3fad136a7a4db4"></a><span class="identifier">reset</span><span class="special">(</span><span class="special">)</span><span class="special">;</span></pre>
<p>Effects: Subsequent uses of the distribution do not depend on values produced by any engine prior to invoking reset. </p>
</li>
</ol></div>
</div>
<div class="refsect2">
<a name="id-1.3.32.5.6.9.3.4.4"></a><h3>
<a name="id-1_3_32_5_6_10_1_1_1_7-bb"></a><code class="computeroutput">discrete_distribution</code> friend functions</h3>
<div class="orderedlist"><ol class="orderedlist" type="1">
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
  <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a6d79d1fa37ce80bf01f5bd5324ace4c3"></a><span class="keyword">operator</span><span class="special">&lt;&lt;</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_ostream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> os<span class="special">,</span> 
             <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> dd<span class="special">)</span><span class="special">;</span></pre>
<p>Writes a distribution to a <code class="computeroutput">std::ostream</code>. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">template</span><span class="special">&lt;</span><span class="keyword">typename</span> CharT<span class="special">,</span> <span class="keyword">typename</span> Traits<span class="special">&gt;</span> 
  <span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> 
  <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a32c7054cca68cc57d265cb419c1f4141"></a><span class="keyword">operator</span><span class="special">&gt;&gt;</span><span class="special">(</span><span class="identifier">std</span><span class="special">::</span><span class="identifier">basic_istream</span><span class="special">&lt;</span> <span class="identifier">CharT</span><span class="special">,</span> <span class="identifier">Traits</span> <span class="special">&gt;</span> <span class="special">&amp;</span> is<span class="special">,</span> 
             <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> dd<span class="special">)</span><span class="special">;</span></pre>
<p>Reads a distribution from a <code class="computeroutput">std::istream</code> </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a3026c723cb18b563ed2b4c43c8cdaa90"></a><span class="keyword">operator</span><span class="special">==</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> lhs<span class="special">,</span> 
                <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> rhs<span class="special">)</span><span class="special">;</span></pre>
<p>Returns true if the two distributions will return the same sequence of values, when passed equal generators. </p>
</li>
<li class="listitem">
<pre class="literallayout"><span class="keyword">bool</span> <a name="doxygen.headers.classboost_1_1random_1_1discrete__distribution_1a119f950ff56eeea03b439d36f6dabd0a"></a><span class="keyword">operator</span><span class="special">!=</span><span class="special">(</span><span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> lhs<span class="special">,</span> 
                <span class="keyword">const</span> <a class="link" href="classboost_1_1random_1_1discrete__distribution.html" title="Class template discrete_distribution">discrete_distribution</a> <span class="special">&amp;</span> rhs<span class="special">)</span><span class="special">;</span></pre>
<p>Returns true if the two distributions may return different sequences of values, when passed equal generators. </p>
</li>
</ol></div>
</div>
</div>
</div>
<div class="copyright-footer">Copyright © 2000-2005 Jens Maurer<br>Copyright © 2009, 2010 Steven Watanabe<br>Copyright © 2022-2025 Matt
      Borland<p>
        Distributed under the Boost Software License, Version 1.0. (See accompanying
        file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
      </p>
</div>
<hr>
<div class="spirit-nav">
<a accesskey="p" href="classboost_1_1random_1_1discard__block__engine.html"><img src="../../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../../boost_random/reference.html#doxygen.headers.discrete__distribution_8hpp"><img src="../../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../../index.html"><img src="../../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="classboost_1_1random_1_1discrete__distribution_1_1param__type.html"><img src="../../../../doc/src/images/next.png" alt="Next"></a>
</div>
</body>
</html>
